package com.wisemoresystem.seal.service;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.task.Task;
import org.springframework.stereotype.Service;

import com.wisemoresystem.seal.base.service.BaseService;
import com.wisemoresystem.seal.model.t_d_verify_config;
import com.wisemoresystem.seal.util.SpringTools;

/**
 * 换人复核开关配置
 * 
 * @author Administrator
 *
 */
@Service
public class DatatransferConfigService extends BaseService {

	@Task(code = "process_configuration2", tip = "待审核的数据移植开关(@cnt)")
	public long selectDatatransferConfig1() {

		String sql = "select count(*) cnt from t_d_datatransfer_config t "
				+ " where t.flag in('审核中','申请中') and t.status=0 ";

		Long cnt = super.getTaskCnt(sql);
				
		return cnt;
	}
	
	//
	public List<Map<String, Object>> selectDatatransferConfig() {
		String sql = "select t.*,tu.uname auname,tv.uname vuname from t_d_datatransfer_config t "
				+ " left outer join t_user tu on t.apply_user_id=tu._id "
				+ " left outer join t_user tv on t.verify_user_id=tv._id "
				+ " where t.status=0 order by t.created asc ";

		List<Map<String, Object>> list = jt.queryForList(sql);
		return list;
	}

	//  查询是否开启开关
	private boolean isStart(String module_name) {
		String hql = "from t_d_verify_config t where t.status=0 and t.name=?";
		t_d_verify_config config = super.findObj(hql, module_name);

		if (config == null) {
			return true;
		}
		return "关闭".equals(config.getFlag()) ? false : true;
	}

	public boolean isApplyStart() {
		return isStart("申请复核");
	}

	public boolean isPushStart() {
		return isStart("印章下发复核");
	}

	public boolean isGetStart() {
		return isStart("印章领用复核");
	}

	public boolean isGetUnMatchStart() {
		return isStart("领用不符复核");
	}

	public boolean isGetUnMatchHandleStart() {
		return isStart("不符处理复核");
	}

	public boolean isTransferStart() {
		return isStart("旧章移植申请复核");
	}

	public static void main(String[] args) {
		DatatransferConfigService s = SpringTools
				.getBean(DatatransferConfigService.class);
		System.err.println(s.isApplyStart());

	}
}
